package com.hzjy.api.controller;

import com.hzjy.api.service.impl.ApiProductServiceImpl;
import com.hzjy.common.core.controller.ApiBaseController;
import com.hzjy.common.core.domain.AjaxResult;
import com.hzjy.common.utils.JSONUtil;
import com.hzjy.common.utils.PageData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@Api("版权交易页")
@RestController
@RequestMapping("/api/copyRight")
public class CopyRightTradeController extends ApiBaseController {
    private static final Logger log = LoggerFactory.getLogger(CopyRightTradeController.class);
    @Autowired
    private ApiProductServiceImpl apiProductService;

    @ApiOperation("产品查询")
    @PostMapping("/query")
    public AjaxResult query(@RequestBody PageData pd) {
        log.info("【版权交易查询】,args:" + JSONUtil.map2json(pd));
        Object currentPage = pd.get("currentPage");
        if (currentPage == null || Integer.parseInt(currentPage.toString()) == 0) {
            pd.put("currentPage", 0);
            pd.put("size",10);
        } else {
            pd.put("currentPage", (Integer.parseInt(pd.get("currentPage").toString()) - 1) * Integer.parseInt(pd.get("size").toString()));
        }
        Map map = apiProductService.getProjectList(pd);
        map.put("currentPage", currentPage); //选择的页数
        return AjaxResult.success(200, "成功", map);
    }
}
